package com.example.music_player_app.ui.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.music_player_app.Bean.PersonalizedResult;
import com.example.music_player_app.R;
import com.example.music_player_app.view.MyImageView;

import java.util.List;

public class MyAdapter extends BaseAdapter {
    private List<PersonalizedResult> list;
    private Context context;

    public MyAdapter(List<PersonalizedResult> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.personalized_item, parent, false);
        }
        MyImageView imageView = convertView.findViewById(R.id.personalized_item_image);
//        imageView.setImageURL(list.get(position).getPicUrl());

        TextView textView = convertView.findViewById(R.id.personalized_item_text);
        textView.setText(list.get(position).getName());

        TextView textView2 = convertView.findViewById(R.id.personalized_item_des);
        textView2.setText(list.get(position).getCopywriter());

        TextView textView3 = convertView.findViewById(R.id.personalized_item_playCount);
        textView3.setText("播放量：" + list.get(position).getPlayCount());
        return convertView;
    }
}
